package com.electron.power.octopus.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.electron.power.model.mod.ModBodyMap;
import com.electron.power.model.mod.ModStr;
import com.electron.power.octopus.repository.ModBodyMapRepository;
import com.electron.power.octopus.repository.ModReactiveRepository;
import com.electron.power.octopus.repository.ModStrRepository;

import lombok.extern.slf4j.Slf4j;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@Service
@Slf4j
public class ModService {
	@Autowired
	private ModBodyMapRepository modBodyRepository;
	
	@Autowired
	private ModStrRepository modStrRepository;
	


	public Mono<ModBodyMap> addModStr(ModStr mod) {
//		if(true) {
//			throw new RuntimeException("测试数据!");
//		}
		return modStrRepository.save(mod).flatMap(m->{
			log.info("存储到数据库中的mod是{}",m);
			ModBodyMap modBodyMap = ModBodyMap.exchange(m);
			return modBodyRepository.save(modBodyMap);
		});
	}

	public Flux<ModStr> findAll() {
		return modStrRepository.findBy();
	}
}
